﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TalentRecruitmentSystem.Service;
using TalentRecruitmentSystem.Manage;

namespace TalentRecruitmentSystem.Pages
{
    public partial class UpdatePsw : System.Web.UI.Page
    {
        string Name = "";
        UserInfoManage um = new UserInfoManage();
        CompanyInfoManage cm = new CompanyInfoManage();
        protected void Page_Load(object sender, EventArgs e)
        {
            //string str = Session["stringInSession"].ToString();
            string str2 = Session["perInSession"].ToString();
            if (str2 != null)
            {
                Name = Session["perInSession"].ToString();
            }
            //if (str != "")
            //{
            //    Name = Session["stringInSession"].ToString();
            //}
            //else if (str2 != null)
            //{
            //    Name = Session["perInSession"].ToString();
            //}
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (Name != null)
            {
                UserInfo userinfo = um.getUserInfoByUserName(Name);
                CompanyInfo companyInfo = new CompanyInfo();
                if (userinfo != null)
                {
                    if (userinfo.Password == TextBox1.Text)
                    {
                        userinfo.Password = TextBox2.Text;
                        um.UpdateUserInfo(userinfo);
                        Response.Write("<script>window.alert('保存成功！');</script>");
                    }
                    else
                    {
                        Response.Write("<script>window.alert('密码输入错误！');</script>");
                    }
                }
                else
                {
                    companyInfo = cm.GetCompanyInfoByName(Name);
                    if (companyInfo.Password == TextBox1.Text)
                    {
                        companyInfo.Password = TextBox2.Text;
                        cm.Update(companyInfo);
                        Response.Write("<script>window.alert('保存成功！');</script>");
                    }
                    else
                    {
                        Response.Write("<script>window.alert('密码输入错误！');</script>");
                    }
                }
            }
            else
                Response.Write("<script>window.alert('页面已过期，请重新载入！');</script>");
        }
    }
}